package com.penngo.gui.dfdiff.view;

import cn.hutool.core.io.FileUtil;
import com.penngo.gui.dfdiff.utils.GB;

import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import java.awt.*;
import java.io.File;

public class RightEditor extends RightPanel{
    private FileEditorPanel Editor;
    public RightEditor(ProjectNode node) {
        super(node);
        File file = node.getPathLeft();
        Editor = new FileEditorPanel(file);
        add(Editor, new GB(0,0,1,1).setFill(GB.BOTH).setWeight(100,100));

//        this.getContentPane().add(Editor);
//        this.addInternalFrameListener(new InternalFrameAdapter() {
//            @Override
//            public void internalFrameClosing(InternalFrameEvent e) {
//                super.internalFrameClosing(e);
//                System.out.println("internalFrameClosing=====");
//                // 窗口关闭时自动保存
//                ProjectNode node = getProjectNode();
//                File curFile = node.getPathLeft();
//                if(curFile != null){
//                    FileUtil.writeString(getEditor().getText(), curFile, "UTF-8");
//                }
//            }
//
//        });
    }

    protected void initUi() {

    }

    public FileEditorPanel getEditor() {
        return Editor;
    }

    public void undo(){
        getEditor().getTextArea().undoLastAction();
    }
    public void redo(){
        getEditor().getTextArea().redoLastAction();
    }
    public void copy(){
        getEditor().getTextArea().copy();
    }
    public void paste(){
        getEditor().getTextArea().paste();
    }
    public void cut(){
        getEditor().getTextArea().cut();
    }
    public void find(){
        getEditor().setFindBarVisiable(true);

    }
    public void setLineWrap(boolean b){
        getEditor().getTextArea().setLineWrap(b);
    }
    public void updateFont(Font font){
        getEditor().getTextArea().setFont(font);
    }
}
